#include "Common.h"

LUAColor::LUAColor(ui8 r, ui8 g, ui8 b) : r(r), g(g), b(b)
{
}

void LUAColor::SetNewColor(ui8 r, ui8 g, ui8 b)
{
	this->r = r;
	this->g = g;
	this->b = b;
}

ui32 LUAColor::GetColorValue()
{
	ui32 colorref = 0x00000000;
	colorref |= b;
	colorref |= (g << 8);
	colorref |= (r << 16);
	return colorref;
}

void LUAColor::SetFixColor(ui8 index)
{
	if(index >= NUM_CLRS)
		return;
	switch(index)
	{
	case CLR_RED:
		SetNewColor(255, 0, 0);
		break;
	case CLR_BLUE:
		SetNewColor(0, 0, 255);
		break;
	case CLR_GREEN:
		SetNewColor(0, 255, 0);
		break;
	}
}

scope LUAColor::RegisterLUAColor()
{
	return
		class_<LUAColor>("LUAColor")
		.def(constructor<ui8, ui8, ui8>())
		.def("SetNewColor", &LUAColor::SetNewColor)
		.def("GetColorVal", &LUAColor::GetColorValue)
		.def("SetFixColor", &LUAColor::SetFixColor)
		.def_readonly("r", &LUAColor::r)
		.def_readonly("g", &LUAColor::g)
		.def_readonly("b", &LUAColor::b)
		.enum_("constants")
		[
			value("COLOR_RED", LUAColor::CLR_RED),
			value("COLOR_BLUE", LUAColor::CLR_BLUE),
			value("COLOR_GREEN", LUAColor::CLR_GREEN)
		];
}

LUAMoney::LUAMoney(ui32 gold, ui32 silver, ui32 copper) : _gold(gold), _silver(silver), _copper(copper)
{
}

void LUAMoney::AddCopper(ui32 val)
{
	_copper += val;
}

void LUAMoney::AddSilver(ui32 val)
{
	_silver += val;
}

void LUAMoney::AddGold(ui32 val)
{
	_gold += val;
}

ui32 LUAMoney::GetCopperVal()
{
	return (Useable::ConvertToCopper(Useable::Money(_gold, _silver, _copper)));
}

scope LUAMoney::RegisterLUAMoney()
{
	return
		class_<LUAMoney>("LUAMoney")
		.def(constructor<ui32, ui32, ui32>())
		.def("AddGold", &LUAMoney::AddGold)
		.def("AddSilver", &LUAMoney::AddSilver)
		.def("AddCopper", &LUAMoney::AddCopper)
		.def("GetMoneyVal", &LUAMoney::GetCopperVal)
		.def(self == self)
		.def(self <= self)
		.def(self <= ui32())
		.def_readwrite("gold", &LUAMoney::_gold)
		.def_readwrite("silver", &LUAMoney::_silver)
		.def_readwrite("copper", &LUAMoney::_copper)
		.def_readwrite("g", &LUAMoney::_gold)
		.def_readwrite("s", &LUAMoney::_silver)
		.def_readwrite("c", &LUAMoney::_copper);
}

scope LUAVector::RegisterLUAVector()
{
	return 
		class_<LUAVector>("LUAVector")
		.def(constructor<float, float, float, int>())
		.def_readwrite("x", &LUAVector::_x)
		.def_readwrite("y", &LUAVector::_y)
		.def_readwrite("z", &LUAVector::_z)
		.def_readwrite("mapid", &LUAVector::_map)
		.def(self == self);
}

scope LUALog::RegisterLUALog()
{
	return
		class_<LUALog>("LUALog")
		.scope
		[
			def("Warning", &LUALog::Warning),
			def("Success", &LUALog::Success),
			def("Error", &LUALog::Error),
			def("Notice", &LUALog::Notice)
		];
}